import { createApp } from "vue"
import ArcoVue from "@arco-design/web-vue"
import ArcoVueIcon from "@arco-design/web-vue/es/icon"
import commonPlugins from "@/plugins/common/index.js"
import plugins from "@/plugins"
import XiriForm from "@/components/xiriForm.vue"
import globalComponents from "@/components"
import App from "./App.vue"
import router from "./router"
import store from "./store"
import i18n from "@/i18n"
import directives from "./directives"
import dayjs from "dayjs"
import zhCn from "dayjs/locale/zh-cn"
import relativeTime from "dayjs/plugin/relativeTime"
dayjs.locale(zhCn)
dayjs.extend(relativeTime)
import DataVVue3 from "@kjgl77/datav-vue3"
// 官方样式
// import '@arco-design/web-vue/dist/arco.css'
// MineAdmin-V2样式
import "@arco-themes/vue-mine-admin-v2/index.less"
import "./style/skin.less"
import "./style/index.css"
import "./style/global.less"
import VxeTable from "vxe-table"
import "vxe-table/lib/style.css"
import VxeUI from "vxe-pc-ui"
import "vxe-pc-ui/lib/style.css"
import tool from "@/utils/tool"
import * as common from "@/utils/common"

const app = createApp(App)

app
  .use(ArcoVue, {})
  .use(ArcoVueIcon)
  .use(VxeTable)
  .use(VxeUI)
  .use(router)
  .use(store)
  .use(i18n)
  .use(directives)
  .use(globalComponents)

// 注册ma-icon图标
const modules = import.meta.glob("./assets/ma-icons/*.vue", { eager: true })
for (const path in modules) {
  const name = path.match(/([A-Za-z0-9_-]+)/g)[2]
  const componentName = `MaIcon${name}`
  app.component(componentName, modules[path].default)
}
app.directive("debounce", {
  mounted(el, binding) {
    el.addEventListener("click", () => {
      if (!el.disabled) {
        el.disabled = true
        setTimeout(() => {
          el.disabled = false
        }, binding.value || 2000)
      }
    })
  }
})
app.component("XiriForm", XiriForm)
commonPlugins(app)
plugins(app)
app.use(DataVVue3)
app.config.globalProperties.$tool = tool
app.config.globalProperties.$common = common
app.config.globalProperties.$title = import.meta.env.VITE_APP_TITLE
app.config.globalProperties.$url = import.meta.env.VITE_APP_IMAGEURL
app.mount("#app")
